package com.example.demo.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Shanks
 * @date 2020-10-22
 */
@Getter
@Setter
@ToString
@ApiModel(value = "BookVO", description = "书籍")
public class BookVO implements Serializable {

    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("编码")
    private String code;

    @ApiModelProperty("书名")
    private String name;

    @ApiModelProperty("作者")
    private String author;

    @ApiModelProperty("预览")
    private PreviewVO preview;

    /**
     * 解决后端字段类型为Long, 前端在解析比较较大的数据时出现超出Number表示范围带来的精度丢失问题
     * 纯使用注解总结出来3个方式:
     * 1.@JsonFormat(shape = JsonFormat.Shape.STRING)
     * 2.@JsonSerialize(using = com.fasterxml.jackson.databind.ser.std.ToStringSerializer.class)
     * 3.@JSONField(serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class)
     * 其中, 2和3方式较为相似, 在Swagger的预览展示上是以整型展示的, 方式1展示效果为字符串, 但是最终显示结果还都是字符串类型的
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @ApiModelProperty("总字数")
    private Long wordTotal;

    @JsonSerialize(using = com.fasterxml.jackson.databind.ser.std.ToStringSerializer.class)
    @ApiModelProperty("印刷次数")
    private Long printTotal;

    @JSONField(serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class)
    @ApiModelProperty("售卖册数")
    private Long saleTotal;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    @ApiModelProperty("创作日期")
    private Date writeDate;

    @ApiModelProperty("线上发售时间")
    private Date saleOnlineTime;

    @ApiModelProperty("创建人")
    private String createBy;

    /**
     * 慢了8个小时
     *
     * "createTime": "2020-10-29 01:52:52"
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("更新人")
    private String updateBy;

    /**
     * ok, 时区正常
     * "updateTime": "2020-10-29 09:52:54"
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty("更新时间")
    private Date updateTime;
}